package com.jcli.jb51_net.article._44733按钮点击切换;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

/**
 * @ClassName XOButton
 * @Description TODO
 * @Author li
 * @Data 2023/12/13 20:35
 * @Version 1.0
 */
class XOButton extends JButton implements ActionListener {
    private ImageIcon X, O;
    byte value = 0;
    URL xr = this.getClass().getResource("./x123.png");
    URL or = this.getClass().getResource("./o123.png");

    public XOButton() {
        X = new ImageIcon("x123.png");
        O = new ImageIcon("o123.png");
        /*if (xr != null && or != null) {
            X = new ImageIcon(xr);
            X = new ImageIcon("./x123.png");
            O = new ImageIcon(or);
            O = new ImageIcon("./o123.png");
        } else {
            // 处理资源加载失败的情况
            System.err.println("Failed to load images.");
        }*/
        this.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        value++;
        value %= 3;
        switch (value) {
            case 0:
                setIcon(null);
                break;
            case 1:
                setIcon(X);
                break;
            case 2:
                setIcon(O);
        }
    }
}
